#include <unistd.h>

#include <utitl/logger.h>
#include <utitl/thread.h>
#include <db/db.h>

#include <HAL/deviceManager.h>
#include <HAL/hal.h>

#include <HAL/functionInterface.h>
#include <HAL/functionFactory.h>
#include <filter/filterFactory.h>
#include <HAL/driverManager.h>

using namespace ECG::Utitl;
using namespace ECG::DB;
using namespace ECG::HAL;
using namespace ECG::Filter;

class Collector: public thread{
    virtual void* run()
    {
        while(1)
        {
            log_debug() << "Runing thread....";
            sleep(1);
        } 
        return NULL;
    }
}; 

static void dbInit()
{
    DB_Redis::instance()->connect("127.0.0.1:6379",NULL,5);
}


int main(int argc,char* argv[])
{

    log_trace()<< "This is trace log";
    log_debug()<< "This is debug log";

    // Collector *collector =  new Collector();
    // if(collector->start())
    // {
    //     log_debug()<< "collector is runing";
    // }
    // sleep(1);
    // if(collector->stop())
    // {
    //     log_debug() << "collector is stop";
    // }
    // collector->wait();
    // for(int i=0;i<2;i++)
    // {
    //     log_info()<<"just see if collector is top";
    //     sleep(1);
    // }
    // delete collector;
#if 0
    dbInit();
    const char* val[] ={"This","is","ok"};
    size_t len[] ={4,2,2};
    log_debug() << "befor lpush";
    
    log_debug() << "lpush ok"<<DB_Redis::instance()->lpush("Hello",val,len,3);
    acl::string valOut;
    DB_Redis::instance()->rpop("Hello",valOut);
    log_debug() << "rpop:" << valOut.c_str();
    
    DB_Redis::instance()->destroy();
    log_debug() << "redis client destroy";
#endif

#if 0 
    DevManagerPtr devManager = DevManager::instance();
    devManager->loadDevice();

    FuncFactoryPtr funcFactory = FuncFactory::instance();
    FuncInterfacePtr func = funcFactory->getFuncByID("ADC_func");
    func->open("Hello");

    //ADC_filter
    FilterFactoryPtr filterFactory = FilterFactory::instance();
    CFilterPtr filter = filterFactory->getFilterByID("ADC_filter");
    filter->start();
#endif 
    //driverManager
    DriverManagerPtr driverManager = DriverManager::instance();
    if(driverManager->loadDrivers())
    {
        log_debug() << "load ok";
    }else
    {
        log_error() << "load err";
    }

    ECG::Utitl::Logger::destroy();
    return 0;
}